package com.sky.controller.admin;

import com.sky.dto.OrdersCancelDTO;
import com.sky.dto.OrdersConfirmDTO;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.pojo.Courier;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.user.OrderService;
import com.sky.vo.OrderStatisticsVO;
import com.sky.vo.OrdersVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;

@RestController("adminOrderController")
@RequestMapping("/admin/order")
@Api(tags = "管理端-订单管理")
@Slf4j
public class OrderController {

    @Autowired
    private OrderService orderService;

    @GetMapping("conditionSearch")
    @ApiOperation("订单分页查询")
    public Result<PageResult<OrdersVO>> pageQuery(OrdersPageQueryDTO queryDTO){
        log.info("订单分页查询 -- {}", queryDTO);

        return orderService.pageQuery(queryDTO);
    }

    /**
     * 统计各个状态的订单数量
     */

    @GetMapping("/statistics")
    @ApiOperation("统计各个状态的订单数量")
    public Result<OrderStatisticsVO> statistics(){
        return orderService.statistics();
    }

    @GetMapping("/details/{orderId}")
    @ApiOperation("根据id查询订单详情")
    public Result<OrdersVO> getDetailById(@PathVariable("orderId") Long orderId) {
        log.info("根据id查询订单详情 -- {}", orderId);

        return orderService.getDetailById(orderId);
    }

    @PutMapping("/cancel")
    @ApiOperation("商家取消订单")
    public Result<String> cancel(@RequestBody OrdersCancelDTO cancelDTO) throws IOException {
        log.info("商家取消订单 -- {}", cancelDTO);

        return orderService.cancelOrder(cancelDTO);
    }

    @PutMapping("/confirm")
    @ApiOperation("商家接单")
    public Result<Courier> confirm(@RequestBody OrdersConfirmDTO confirmDTO){
        log.info("商家取消订单 -- {}", confirmDTO);

        return orderService.confirm(confirmDTO);
    }
}
